package me.obstsalatt.guildera2.core;

/**
 * Created with IntelliJ IDEA.
 * User: Robin
 * Date: 13.02.14, 23:25
 * Project: GuildEra2
 * Package: me.obstsalatt.guildera2
 * Descriprion:
 *      Describes the owner of a certain something
 */
public class Owner {
    private String name;
    private boolean isGuild;
    private boolean isPlayer;
    private boolean isWorld;

    public Owner() {
        this.name = "$default";
        isGuild = false;
        isPlayer = false;
        isWorld = true;
    }

    public Owner(String name, int type) {
        this.name = name;
        if(type == 0) {
            isGuild = false;
            isPlayer = false;
            isWorld = false;
        } else if(type == 1) {
            isGuild = false;
            isPlayer = true;
            isWorld = false;
        } else if(type == 2) {

            isGuild = true;
            isPlayer = false;
            isWorld = false;
        }
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Owner owner = (Owner) o;

        if (isGuild != owner.isGuild) return false;
        if (isPlayer != owner.isPlayer) return false;
        if (isWorld != owner.isWorld) return false;
        if (!name.equals(owner.name)) return false;

        return true;
    }

    public int hashCode() {
        int result = name.hashCode();
        result = 31 * result + (isGuild ? 1 : 0);
        result = 31 * result + (isPlayer ? 1 : 0);
        result = 31 * result + (isWorld ? 1 : 0);
        return result;
    }

    public boolean isGuild() {
        return isGuild;
    }

    public boolean isPlayer() {
        return isPlayer;
    }

    public boolean isWorld() {
        return isWorld;
    }

    public boolean isDefault() {
        return name.equals("$default");
    }

    public String getName() {
        return name;
    }

    public int getType() {
        if(isWorld)     { return 0; }
        if(isPlayer)    { return 1; }
        if(isGuild)     { return 2; }
        return 0;
    }
}
